package main

import (
	"encoding/json"
	"fmt"
	"github.com/kirinlabs/HttpRequest"
	"time"
)

// 定义返回值的解码
type ResponseData struct {
	Data int `json:"data"`
}

func Add(a, b int) int {
	// 获取http请求方法
	req := HttpRequest.NewRequest()
	//发起get请求
	res, _ := req.SetTimeout(time.Second * 10).Get(fmt.Sprintf("http://127.0.0.1:8080/%s?a=%d&b=%d", "add", a, b))
	//获取返回体
	body, _ := res.Body()
	//初始化
	rspData := ResponseData{}
	//获取json
	_ = json.Unmarshal(body, &rspData)
	return rspData.Data
}

func main() {
	fmt.Println(Add(2, 2))
}
